//
//  TopImgBtnView.m
//  ocCrazy
//
//  Created by 山上山下 on 2018/10/16.
//  Copyright © 2018 dukai. All rights reserved.
//

#import "TopImgBtnView.h"

@implementation TopImgBtnView
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    _img = [UIImageView new];
    [self addSubview:_img];
    _img.userInteractionEnabled = YES;
    _img.frame = CGRectMake(0, aufont(14), aufont(23), aufont(23));
    _img.centerX = self.centerX - self.left;
    
    _titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, _img.bottom + aufont(11), self.width, aufont(12))];
    [self addSubview:_titleLab];
    _titleLab.centerX = self.centerX - self.left;
    _titleLab.font = R_Font(12);
    _titleLab.textAlignment = NSTextAlignmentCenter;
}

- (void)imgWidthHeight:(CGFloat)wh {
    self.img.width = wh;
    self.img.height = wh;
    self.img.centerX = self.centerX - self.left;
    self.titleLab.frame = CGRectMake(0, _img.bottom + aufont(11), self.width, aufont(12));
    _titleLab.centerX = self.centerX - self.left;
}

- (void)imgFrame:(CGRect)frame {
    self.img.frame = frame;
    self.titleLab.frame = CGRectMake(0, _img.bottom + aufont(11), self.width, aufont(12));
    _titleLab.centerX = self.centerX - self.left;
}

- (void)titleLabFrame:(CGRect)frame {
    self.titleLab.frame = frame;
    _titleLab.centerX = self.centerX - self.left;
}

- (void)imgContainerTopSpace:(CGFloat)space {
    self.img.top = space;
    self.titleLab.frame = CGRectMake(0, _img.bottom + aufont(11), self.width, aufont(12));
    _titleLab.centerX = self.centerX - self.left;
}

- (void)imgLabSpace:(CGFloat)space {
    self.titleLab.top = self.img.bottom + space;
}

- (void)addTapGestureTarget:(id)target action:(SEL)selector {
    if (!selector) { return; }
    if (!target) { return; }
    _tap = [[UITapGestureRecognizer alloc] initWithTarget:target action:selector];
    [self addGestureRecognizer:self.tap];
}
@end
